package work.chief.backend.core.builder.sql;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 封装字段名
 */
@Component
public class MySQLDialect implements SQLDialect {

//    包装字段名
    @Override
    public String warpFieldName(String name) {
        return String.format("`%s`",name);
    }

//    解析字段名
    @Override
    public String parseFieldName(String fieldName) {
        if (fieldName.startsWith("`") && fieldName.endsWith("`")) {
            return fieldName.substring(1, fieldName.length() - 1);
        }
        return fieldName;
    }

//    包装表名
    @Override
    public String wrapTableName(String name) {
        return String.format("`%s`",name);
    }

//    解析表名
    @Override
    public String parseTableName(String tableName) {
        if (tableName.startsWith("`") && tableName.endsWith("`")) {
            return tableName.substring(1, tableName.length() - 1);
        }
        return tableName;
    }
}
